An excavator which is one of construction machines includes a running body, an upper swing body that is provided on the running body in a swingable manner, and a working machine that is provided on the upper swing body. The working machine includes a boom of which one end is journaled onto a base portion, an arm of which one end is journaled to the other end of the boom, and an attachment that is journaled to the other end of the arm. The boom, the arm, and the attachment are driven by hydraulic cylinders. In order to detect the position and the posture of the working machine, the stroke of the hydraulic cylinder is measured.
For example, Patent Literature 1 discloses an excavator with a position sensor that detects a piston stroke position of the hydraulic cylinder driving the working machine by the rotation of a rotation roller on a cylinder rod. Since a slight slip occurs between the rotation roller and the cylinder rod, an error occurs between the actual stroke position and the stroke position obtained from the detection result of the position sensor. Therefore, in order to calibrate the stroke position obtained from the detection result of the position sensor to the reference position, a magnetic sensor as a reset sensor is provided at the reference position of an outer surface of a cylinder tube of the hydraulic cylinder. The stroke position which is detected by the position sensor when the piston passes by the reference position during the work is calibrated, and hence the accurate position may be measured.